From 0a358d4a5537a5e71dad08a8904ad6db100a7927 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Sun, 2 Jan 2022 03:50:13 +0100
Subject: [PATCH] simple readiness mechanism that we can use with dinit

---
 lib/service-management.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/service-management.c b/lib/service-management.c
index 1fbfdbd..58441be 100644
--- a/lib/service-management.c
+++ b/lib/service-management.c
@@ -24,11 +24,14 @@
 #include "service-management.h"
 #include "messages.h"
 
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #if SYSLOG_NG_ENABLE_SYSTEMD
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 #include <systemd/sd-daemon.h>
 
 #endif
@@ -127,6 +130,13 @@ service_management_dummy_clear_status(void)
 static inline void
 service_management_dummy_indicate_readiness(void)
 {
+  const gchar *rvar = g_getenv("SYSLOG_NG_READY_FD");
+  if (!rvar) return;
+  int fdnum = atoi(rvar);
+  errno = 0;
+  if (!fdnum || fcntl(fdnum, F_GETFD) < 0 || errno == EBADF)
+    return;
+  write(fdnum, "READY=1", sizeof("READY=1") - 1);
 }
 
 static gboolean
-- 
2.34.1

